package com.wanhe.viewconf.views.child;

import android.content.Context;
import android.widget.LinearLayout;

import com.wanhe.base.model.disgn.Event;
import com.wanhe.base.model.disgn.ViewEvent;
import com.wanhe.viewconf.EventManager;
import com.wanhe.viewconf.views.child.interfaces.IViewOperations;

/**
 * File Name:BaseXYView.java<br/>
 * Package Name:com.wanhe.viewconf.views<br/>
 * Date:2017/7/4 13:55<br/>
 * author:chendeji<br/>
 * desc: <br/>
 * Copyright (c) 2017/7/4, 781571323@qq.com All Rights Reserved.
 */
public abstract class BaseXYView extends LinearLayout implements IXYView , IViewOperations {
	private double			mLeftPt;
	private double			mTopPt;
	private double			mWidthPt;
	private double			mHeightPt;

	public static final int	VIEW_INIT	= 0;
	public static final int	VIEW_DIRTY	= 1;
	public static final int	VIEW_CLEAR	= 2;

	private int				viewStatu;

	private int				mRealWidth;

	private int				mRealHeight;

	@Override
	public double getLeftPT() {
		return this.mLeftPt;
	}

	@Override
	public void setLeftPT(double left) {
		this.mLeftPt = left;
	}

	@Override
	public double getTopPT() {
		return this.mTopPt;
	}

	@Override
	public void setTopPT(double top) {
		this.mTopPt = top;
	}

	@Override
	public double getWidthPT() {
		return this.mWidthPt;
	}

	@Override
	public void setWidthPT(double width) {
		this.mWidthPt = width;
	}

	@Override
	public double getHeightPT() {
		return this.mHeightPt;
	}

	@Override
	public void setHeightPT(double height) {
		this.mHeightPt = height;
	}

	@Override
	public int[] transpRect(double left, double top, double right, double bottom) {
		int[] rect = new int[4];
		rect[0] = (int) (left * extendScale);
		rect[1] = (int) (top * extendScale);
		rect[2] = (int) (right * extendScale);
		rect[3] = (int) (bottom * extendScale);
		return rect;
	}

	private double extendScale = 1;

	public double getExtendScale() {
		return extendScale;
	}

	public void setExtendScale(double extendScale) {
		this.extendScale = extendScale;
	}

	public BaseXYView(Context context) {
		super(context);
		setViewStatu(VIEW_INIT);
	}

	public int getViewStatu() {
		return viewStatu;
	}

	public void setViewStatu(int viewStatu) {
		this.viewStatu = viewStatu;
	}

	public void setRealWidth(int width) {
		this.mRealWidth = width;
	}

	public void setRealHeight(int height) {
		this.mRealHeight = height;
	}

	public int getRealHeight() {
		return mRealHeight;
	}

	public int getRealWidth() {
		return mRealWidth;
	}

	/**
	 * Methor Name:onEvent<br/>
	 * Package Name:com.wanhe.viewconf.views.child<br/>
	 * Date:2017/7/11 11:42<br/>
	 * author:chendeji<br/>
	 * desc: 父控件会将事件分发到子控件上，主要是通过这个方法将事件下发至各个子控件，子控件将事件继续传递至
	 * {@link com.wanhe.viewconf.EventManager}的事件处理方法。<br/>
	 * Copyright (c) 2017/7/11, 781571323@qq.com All Rights Reserved.
	 *
	 * @param event
	 *            接受到的事件
	 * @param coor
	 *            发送事件的控件坐标
	 * @return
	 */
	public void onEvent(Event event, ViewEvent.Coor coor) {
		// TODO: 2017/7/11 将事件发送到事件管理器中进行处理
		EventManager.getInstance().onReceiveEvent(this, event, coor);
	}

	public void onEvent(String eventName, Event event, ViewEvent.Coor coor) {
		EventManager.getInstance().onReceiveEvent(this, eventName, event, coor);
	}

}
